<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改生字管理')" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-zi-edit" th:object="${zi}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-2 control-label">字：</label>
                <div class="col-sm-10">
                    <input name="zi" th:field="*{zi}" class="form-control" type="text" style="pointer-events: none;">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">部首：</label>
                <div class="col-sm-10">
                    <input name="zi" th:field="*{bushou}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">总比划：</label>
                <div class="col-sm-10">
                    <input name="zi" th:field="*{zongbihua}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">部外笔划：</label>
                <div class="col-sm-10">
                    <input name="zi" th:field="*{buwaibihua}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">简体字：</label>
                <div class="col-sm-10">
                    <input name="zi" th:field="*{jtz}" class="form-control" type="text" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">繁体字：</label>
                <div class="col-sm-10">
                    <input name="zi" th:field="*{fzi}" class="form-control" type="text" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">拼音(无声调)：</label>
                <div class="col-sm-10">
                    <input name="zi" th:field="*{py}" class="form-control" type="text" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">拼音(带声调)：</label>
                <div class="col-sm-10">
                    <input name="zi" th:field="*{pinyin}" class="form-control" type="text" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">五笔：</label>
                <div class="col-sm-10">
                    <input name="zi" th:field="*{wubi}" class="form-control" type="text" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">五笔(86)：</label>
                <div class="col-sm-10">
                    <input name="zi" th:field="*{wubi86}" class="form-control" type="text" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">五笔(98)：</label>
                <div class="col-sm-10">
                    <input name="zi" th:field="*{wubi98}" class="form-control" type="text" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">结构：</label>
                <div class="col-sm-10">
                    <select id="jiegou" name="jiegou" class="form-control m-b" th:with="type=${@dict.getType('zi_jiegou')}" >
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{jiegou}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">外研社：</label>
                <div class="col-sm-10">
                    <input id="wys" name="wys" type="hidden" th:field="*{wys}" >
                    <div id="wysEditor" class="summernote"></div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">注解(汉典解释)：</label>
                <div class="col-sm-10">
                    <input id="zhujie" name="zhujie" type="hidden" th:field="*{zhujie}" >
                    <div id="zhujieEditor" class="summernote"></div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-2 control-label">详解：</label>
                <div class="col-sm-10">
                    <input id="xiangjie" name="xiangjie" type="hidden" th:field="*{xiangjie}" >
                    <div id="xiangjieEditor" class="summernote"></div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-2 control-label">古汉语：</label>
                <div class="col-sm-10">
                    <input id="guhanyu" name="guhanyu" type="hidden" th:field="*{guhanyu}" >
                    <div id="guhanyuEditor" class="summernote"></div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">国语词典：</label>
                <div class="col-sm-10">
                    <input id="gycd" name="gycd" type="hidden" th:field="*{gycd}" >
                    <div id="gycdEditor" class="summernote"></div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: summernote-js" />
    <script src="/js/standalone.js"></script>
    <script src="/js/parser-html.js"></script>
    <script type="text/javascript">
        var prefix = ctx + "dict/zi";
        $("#form-zi-edit").validate({
            focusCleanup: true
        });

        function prettierFormat(html) {
            try{
                if(prettier == null || prettierPlugins == null) {
                  return html;
                }
                return prettier.format(html, {
                  parser: "html",
                  plugins: prettierPlugins
                });
            }catch(error){
               return html;
            }
        }

        $(function() {
			$('.summernote').summernote({
				placeholder : '请输入内容',
				height : 400,
				lang : 'zh-CN',
				followingToolbar : false,
				callbacks : {
					onImageUpload : function(files) {

					}
				}
			});

			var wys = $("#wys").val();
			$('#wysEditor').summernote('code', prettierFormat(wys));

			var xiangjie = $("#xiangjie").val();
			$('#xiangjieEditor').summernote('code', prettierFormat(xiangjie));

			var guhanyu = $("#guhanyu").val();
			$('#guhanyuEditor').summernote('code', prettierFormat(guhanyu));

			var gycd = $("#gycd").val();
			$('#gycdEditor').summernote('code', prettierFormat(gycd));

			var zhujie = $("#zhujie").val();
			$('#zhujieEditor').summernote('code', prettierFormat(zhujie));
		});

        function submitHandler() {
            if ($.validate.form()) {
                var xiangjie = $('#xiangjieEditor').summernote('code');
				$("#xiangjie").val(xiangjie);

				var guhanyu = $('#guhanyuEditor').summernote('code');
				$("#guhanyu").val(guhanyu);

				var gycd = $('#gycdEditor').summernote('code');
				$("#gycd").val(gycd);

				var zhujie = $('#zhujieEditor').summernote('code');
				$("#zhujie").val(zhujie);

				var wys = $('#wysEditor').summernote('code');
				$("#wys").val(wys);

				$.operate.save(prefix + "/edit", $('#form-zi-edit').serialize());
            }
        }
    </script>
</body>
</html>